from business.register_business import RegisterBusiness
from selenium import webdriver
import unittest
import os
import HTMLTestRunner
import ddt
from util.excel_util import ExcelUtil


ex = ExcelUtil()
data = ex.get_data()

@ddt.ddt
class FirstDdtCase(unittest.TestCase):

    def setUp(self):
        print('case前置条件')
        self.driver = webdriver.Chrome()
        self.driver.get('http://www.5itest.cn/register')
        self.register = RegisterBusiness(self.driver)


    def tearDown(self):
        print('case后置条件')
        for method_name,error in self._outcome.errors:
            if error:
                case_name = self._testMethodName
                file_path = os.path.join('E:/study/autostudy/image'+case_name+'.png')
                self.driver.save_screenshot(file_path)

        self.driver.close()

    # @ddt.data(
    #
    #     ['224138170','wyu0430','111111','code','email_error','请输入有效的电子邮件地址'],
    #     ['@qq.com', 'wyu0430', '111111', 'code', 'email_error', '请输入有效的电子邮件地址'],
    #     ['224138170@qq.coom', 'wyu0430', '111111', 'code', 'email_error', '请输入有效的电子邮件地址']
    # )
    # @ddt.unpack

    @ddt.data(*data)
    def test_register_case(self,data):
        email, username, password, code, assertCode, assertText = data
        email_error = self.register.register_function(str(email),username,str(password),code,assertCode,assertText)
        self.assertFalse(email_error,'case执行失败')


if __name__ == '__main__':
    file_path = 'E:/study/autostudy/report/first_case_ddt.html'
    f = open(file_path, 'wb')
    suite = unittest.TestLoader().loadTestsFromTestCase(FirstDdtCase)
    runner = HTMLTestRunner.HTMLTestRunner(stream=f, title='report', description="ddt测试报告", verbosity=2)
    runner.run(suite)
